<?php 
/**************************************************/
## Class Name - Model_FAQ (Contains all the functions related FAQ modules)
## Created By - Techmodi (22/08/2011)
/**************************************************/
class Model_FAQ extends Database
{	
	function Model_FAQ() {	
		$this->faqs = FAQS;
		$this->faqs_cat = FAQ_CATEGORIES;
		$this->Database();
	}
	
	// for add FAQ
	function addFaq($array) {
		$this->InsertData($this->faqs, $array);
	}
	
	## List all Faqs
	function getAllFaqs($search,$search_faqcat,$limit='',$offset='') {
		$fields = array();	
		$tables = array($this->faqs);
		if(trim($search)) {
			$where[] = "faq_question LIKE '%".$search."%'";
		}
		if($search_faqcat!=0) {
			$where[] = "faq_category_id=$search_faqcat";
		}
		$result1 = $this->SelectData($fields,$tables, $where , $order = array(), $group=array(),$limit,$offset,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	
	## Get faq details by id
	function getFaqDetailsById($id) {
		$fields = array();	
		$tables = array($this->faqs);
		$result1 = $this->SelectData($fields,$tables, $where= array("faq_id=$id"), $order = array(), $group=array(),$limit = "",0,0); 
		$result  = $this->FetchRow($result1); 
		return $result;
	}
	
	## Edit FAQ by id
	function editFaqById($array, $Id){
		$this->UpdateData($this->faqs,$array,"faq_id",$Id,0);
	}
	
	## Update faq status with multiple ids
	function updateFaqStatus($ids, $status) {
		$sql = "UPDATE ".$this->faqs." SET faq_status='".$status."' WHERE faq_id IN (".$ids.")";
		$result1= $this->ExecuteQuery($sql);	 
		
	}
	
	## Delete faq with multiple ids
	function deleteFaq($ids, $status) {
		$sql = "DELETE FROM ".$this->faqs." WHERE faq_id IN (".$ids.")";
		$result1= $this->ExecuteQuery($sql);	 
	}
	
	## Delete faq cat by id
	function deleteFaqById($id){
		$this->DeleteData($this->faqs,"faq_id",$id);
	}
	
	/****************************************************/
	// for add FAQ
	function addFaqCategory($array) {
		$this->InsertData($this->faqs_cat, $array);
	}
	
	## List all Faqs
	function getAllFaqsCategory($search, $limit='',$offset='') {
		$fields = array();	
		$tables = array($this->faqs_cat);
		$where= array();
		if(trim($search)!='') {
			$where[] = "faq_category LIKE '%".trim($search)."%'";
		}
		
		$result1 = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(),$limit,$offset,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	
	## Get faq details by id
	function getFaqCategoryDetailsById($id) {
		$fields = array();	
		$tables = array($this->faqs_cat);
		$result1 = $this->SelectData($fields,$tables, $where= array("id=$id"), $order = array(), $group=array(),$limit = "",0,0); 
		$result  = $this->FetchRow($result1); 
		return $result;
	}
	
	## Edit FAQ by id
	function editFaqCategoryById($array, $Id){
		$this->UpdateData($this->faqs_cat,$array,"id",$Id,0);
	}
	
	## Update faq status with multiple ids
	function updateFaqCategoryStatus($ids, $status) {
		$sql = "UPDATE ".$this->faqs_cat." SET status='".$status."' WHERE id IN (".$ids.")";
		$result1= $this->ExecuteQuery($sql);	 
	}
	
	## Delete faq category with multiple ids
	function deleteFaqCategory($ids) {
		$sql = "DELETE FROM ".$this->faqs_cat." WHERE id IN (".$ids.")";
		$result1= $this->ExecuteQuery($sql);	 
	}
	
	## Delete faq cat by id
	function deleteFaqCategoryById($id){
		$this->DeleteData($this->faqs_cat,"id",$id);
	}
	
	## List all Faqs Category name
	function getAllFaqsCategoryWithActiveStatus() {
		$fields = array('');	
		$tables = array($this->faqs_cat);
		$where= array("status='1'");
		$result1 = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(),$limit,$offset,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	
	## Get faq details by id
	function getFaqCategoryNameById($id) {
		$fields = array('faq_category');	
		$tables = array($this->faqs_cat);
		$result1 = $this->SelectData($fields,$tables, $where= array("id=$id"), $order = array(), $group=array(),$limit = "",0,0); 
		$result  = $this->FetchRow($result1); 
		return $result['faq_category'];
	}

}
?>


